package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.BusinessService;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.query.BusinessQuery;
import com.tarena.lbs.pojo.basic.vo.BusinessCategoryVO;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    //商家分页列表查询
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> businessPage(BusinessQuery query)
        throws BusinessException{
        PageResult<BusinessVO> voPages = businessService.businessPage(query);
        return new Result<>(voPages);
    }

    //商家行业分类的list查询 查询所有
    @GetMapping("/admin/basic/business/category/list")
    public Result<List<BusinessCategoryVO>> getAllCats() throws BusinessException{
        List<BusinessCategoryVO> vos = businessService.getAllCats();
        return new Result<>(vos);
    }

    //新增商家 不是表单格式 使用json格式
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> businessSave(@RequestBody BusinessParam param) throws BusinessException{
        businessService.businessSave(param);
        return Result.success();
    }

}
